<template>
	<view>
		
	</view>
</template>

<script>
	// import COS from 'cos-js-sdk-v5'
	// const cos = new COS({
	// 	SecretId: 'AKIDQly1gCZlutmV3RfnkUyEFNHwMYXIp9HA',
	// 	SecretKey: 'hAfwyUpwpTu76qMGuLZaNwITQ8bp6B3i',
	// })
	// const Bucket = 'gpt-1255529221';  /* 存储桶 */
	// const Region = 'ap-beijing';  /* 存储桶所在地域，必须字段 */
	export default {
		name:"uploadImg",
		data() {
			return {
				Prefix:'gpt-'
			};
		},
		onLoad() {
			
		},
		methods: {
			upload(callback) {
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFiles = chooseImageRes.tempFiles;
						console.log(chooseImageRes,'chooseImageRes')
						const imgs = tempFiles.map(file => {
							const path = file.webkitRelativePath || file.name;
							  return {
								Bucket,
								Region,
								Key: this.Prefix + path,
								Body: file,
							  }
						})
						cos.uploadFiles({
						  files: imgs,
						  SliceSize: 1024 * 1024 * 10,    /* 设置大于10MB采用分块上传 */
						  onProgress: function (info) {
							  var percent = parseInt(info.percent * 10000) / 100;
							  var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
							  console.log('进度：' + percent + '%; 速度：' + speed + 'Mb/s;');
						  },
						  onFileFinish: function (err, data, options) {
							  console.log(options.Key + '上传' + (err ? '失败' : '完成'));
							  console.log(data)
							  callback(`http://${data.Location}`)
						  },
					   }, (err, data) => {
						  if (err) {
							console.log('上传失败', err);
							return;
						  }
					   });
					}
				});
			}
		}
	}
</script>

<style lang="scss">

</style>